package com.ztej.query.activity;

import android.app.Activity;
import android.app.ProgressDialog;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.KeyEvent;
import android.webkit.WebView;
import android.webkit.WebViewClient;

import com.ztej.query.R;

public class WebViewActivity extends Activity {

    private WebView wvHrqylm;
    private ProgressDialog progressBar;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_web_view);
        initViews();

        progressBar = new ProgressDialog(this);
        progressBar.setCancelable(false);
        progressBar.setMessage("数据加载中 ...");
        progressBar.setProgressStyle(ProgressDialog.STYLE_SPINNER);
        progressBar.setProgress(0);
        progressBar.setMax(100);
        progressBar.show();

        wvHrqylm.getSettings().setJavaScriptEnabled(true);
        wvHrqylm.loadUrl("http://192.168.1.85/web/20170112ruiKaAPP03/help01.html");
        wvHrqylm.setWebViewClient(new HelloWebViewClient());



    }

    private void initViews(){
        wvHrqylm = (WebView) findViewById(R.id.wvHrqylm);

    }


    @Override
    //设置回退
    //覆盖Activity类的onKeyDown(int keyCoder,KeyEvent event)方法
    public boolean onKeyDown(int keyCode, KeyEvent event) {
        if ((keyCode == KeyEvent.KEYCODE_BACK) && wvHrqylm.canGoBack()) {
//            if(wv_Game.canGoBack()){
            wvHrqylm.goBack(); //goBack()表示返回WebView的上一页面
//            }else {
//                finish();
//            }

            return true;
        }else {
            finish();
        }
        return false;
    }

    //Web视图
    private class HelloWebViewClient extends WebViewClient {
        @Override
        public boolean shouldOverrideUrlLoading(WebView view, String url) {
            view.loadUrl(url);
            return true;
        }

        @Override
        public void onPageFinished(WebView view,String url)
        {
            progressBar.cancel();
        }

    }



}
